/*
 Transistor and Stepper Control
 */
#include <Stepper.h>

const int stepsPerRevolution = 100;  // change this to fit the number of steps per revolution
                                     // for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,9,10,11);  

int tpin = 13;
int serialValue = LOW;
//int speet = 0;

void setup() {                
  
  pinMode(tpin, OUTPUT);
  digitalWrite(tpin,LOW);  
    // set the speed at 60 rpm:
  myStepper.setSpeed(30);
  // initialize the serial port:
  Serial.begin(9600);
}


void loop() {
  Serial.print(analogRead(3));
  if(Serial.available()>0){
   serialValue = Serial.read();
    if(serialValue == 49 || serialValue == 107){ //1 or k
      //Serial.print(" Go");
      //Serial.print(serialValue);
      digitalWrite(tpin,HIGH);
    }
    else if(serialValue == 48 || serialValue == 108){ //0 or L
      //Serial.print(" Stop");
      //Serial.print(serialValue);
      digitalWrite(tpin,LOW);
    }
    else if(serialValue == 120){ //left x
      //Serial.print(" Left");
      //Serial.print(serialValue);
      myStepper.step(20);
      
    }
    else if(serialValue == 99){ //right c
      //Serial.print(" Right");
      //Serial.print(serialValue);
      myStepper.step(-20);
    }
     else if(serialValue == 122){ //super left z
      //Serial.print(" SuperLeft");
      //Serial.print(serialValue);
      myStepper.step(40);
      
    }
    else if(serialValue == 118){ //super right v
      //Serial.print(" SuperRight");
      //Serial.print(serialValue);
      myStepper.step(-40);
    }
  }
  
 // while(Serial.available() > 0){
  // speed = (int)Serial.read() + 99; 
  // Serial.println(speed);
  // analogWrite(tpin,speed);
  //}
    // step one revolution  in one direction:
    /*
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);
  
   // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500); 
  */
}
